package com.lxl.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;

import com.lxl.model.Tieba;
import com.lxl.service.TiebaService;
import com.opensymphony.xwork2.ActionContext;

/**
 * 贴吧_列出贴吧Action
 * 
 * @author 刘星鹭
 * @Email liuxinglumail@163.com
 * @version 创建时间： 2014年9月9日 下午4:53:32
 */
@Controller
@Transactional
public class ListTiebaAction {
    @Resource
    TiebaService tiebaService;// 注入贴吧Service
    private List<Tieba> tiebaList;// 贴吧列表
    private int pageNow = 1;// 当前页数
    private int pageCount = 0;// 总页数

    /**
     * 调用本Action时执行本方法
     * 
     * @return 用于Action判断跳转方向的字符串
     */
    public String execute() {
        ActionContext context = ActionContext.getContext();// 获取action上下文
        HttpServletRequest request = (HttpServletRequest) context
                .get(ServletActionContext.HTTP_REQUEST);
        pageCount = tiebaService.pageCount();
        request.setAttribute("pageCount", pageCount);
        request.setAttribute("pageNow", pageNow);
        tiebaList = tiebaService.listTen(pageNow);
        return "success";
    }

    /**
     * 获得贴吧列表
     * 
     * @return 贴吧列表
     */
    public List<Tieba> getTiebaList() {
        return tiebaList;
    }

    /**
     * 设置贴吧列表
     * 
     * @param tiebaList
     *            贴吧列表
     */
    public void setTiebaList(List<Tieba> tiebaList) {
        this.tiebaList = tiebaList;
    }

    /**
     * 获得当前页数
     * 
     * @return 当前页数
     */
    public int getPageNow() {
        return pageNow;
    }

    /**
     * 设置当前页数
     * 
     * @param pageNow
     *            当前页数
     */
    public void setPageNow(int pageNow) {
        this.pageNow = pageNow;
    }

    /**
     * 获得总页数
     * 
     * @return 总页数
     */
    public int getPageCount() {
        return pageCount;
    }

    /**
     * 设置总页数
     * 
     * @param pageCount
     *            总页数
     */
    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }
}
